package com.zed.code.service.impl;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zed.code.base.TRequest;
import com.zed.code.base.TResponse;
import com.zed.code.mapping.*;
import com.zed.code.model.*;
import com.zed.code.request.*;
import com.zed.code.response.*;
import com.zed.code.service.QueryService;
import com.zed.code.util.TokenUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.*;

@Service("queryService")
public class QueryServiceImpl implements QueryService {

    private Logger log = Logger.getLogger(QueryServiceImpl.class);

    @Resource
    private TStationinfoMapper tStationinfoMapper;
    @Resource
    private TPricepartdescMapper tPricepartdescMapper;
    @Resource
    private TEquipmentinfoMapper tEquipmentinfoMapper;
    @Resource
    private TConnectorinfoMapper tConnectorinfoMapper;
    @Resource
    private PowerstationMapper powerstationMapper;
    @Resource
    private DevicestatusinfoMapper devicestatusinfoMapper;
    @Resource
    private JfpgpriceMapper jfpgpriceMapper;
    @Resource
    private PricehistoryMapper pricehistoryMapper;
    @Resource
    private ChargesessionMapper chargesessionMapper;
    @Resource
    private OrderMapper orderMapper;


    private final static Integer tokenAvailableTime = 172800;//token默认有效时间 48小时

    private final static String OPERATOR_ID = "314838869"; //组织机构代码(企业名称，营业执照)：

    public TResponse<TokenInfo> query_token(TRequest<TokenReq> tReq) throws IOException {
        TokenReq req = tReq.getData();
        String req_operatorID = req.getOperatorID();
        ObjectMapper objectMapper = new ObjectMapper();
        TokenInfo tokenInfo = new TokenInfo();
        tokenInfo.setAccessToken(TokenUtil.genToken());
        tokenInfo.setTokenAvailableTime(tokenAvailableTime);
        tokenInfo.setOperatorID(OPERATOR_ID);
        tokenInfo.setFailReason(0);
        tokenInfo.setSuccStat(0);
        TResponse<TokenInfo> resp = genSuccessResp(tokenInfo);

        return resp;
    }

    public TResponse<StationInfoPage> queryStationsInfo(StationsInfo stationsInfo, String operatorId) throws IOException {
        StationInfoPage stationInfoPage = new StationInfoPage();
        //查询充电站信息
        Page page = PageHelper.startPage(stationsInfo.getPageNo(), stationsInfo.getPageSize(), true).setOrderBy("StationID");
        //根据id查询出需要返回的站点


        List<TStationinfo> tStationinfos=tStationinfoMapper.selectByStationId(operatorId);

        List<StationInfo> stationInfos = new ArrayList<StationInfo>();
        for (TStationinfo tStationinfo:tStationinfos){
            StationInfo stationInfo = new StationInfo();
            stationInfo.setRemark(tStationinfo.getRemark());
            stationInfo.setSupportOrder(tStationinfo.getSupportorder());
            stationInfo.setPayment(tStationinfo.getPayment());
            stationInfo.setParkFee(tStationinfo.getParkfee());
            stationInfo.setServiceFee(String.valueOf(tStationinfo.getServicefee()));
            stationInfo.setElectricityFee(String.valueOf(tStationinfo.getElectricityfee()));
            stationInfo.setTimeType(tStationinfo.getTimetype());
            stationInfo.setBusineHours(tStationinfo.getBusinehours());
            stationInfo.setOpenAllDay(tStationinfo.getOpenallday());
            stationInfo.setDataSourceID(OPERATOR_ID);//九位组织机构代码
            stationInfo.setParkInfo(tStationinfo.getParkinfo());
            stationInfo.setMatchCars(tStationinfo.getMatchcars());
            stationInfo.setConstruction(tStationinfo.getConstruction());
            stationInfo.setSiteGuide(tStationinfo.getSiteguide());
            stationInfo.setStationLat(tStationinfo.getStationlat());
            stationInfo.setStationLng(tStationinfo.getStationlng());
            stationInfo.setParkNums(tStationinfo.getParknums());
            stationInfo.setStationStatus(tStationinfo.getStationstatus());
            stationInfo.setStationType(tStationinfo.getStationtype());
            stationInfo.setServiceTel(tStationinfo.getServicetel());
            stationInfo.setStationTel(tStationinfo.getStationtel());
            stationInfo.setAddress(tStationinfo.getAddress());
            stationInfo.setAreaCode(tStationinfo.getAreacode());
            stationInfo.setCountryCode(tStationinfo.getCountrycode());
            stationInfo.setStationName(tStationinfo.getStationname());
            stationInfo.setEquipmentOwnerID(tStationinfo.getEquipmentownerid());
            stationInfo.setOperatorID(tStationinfo.getOperatorid());
            stationInfo.setStationID(tStationinfo.getStationid());
            stationInfo.setPictures(new ArrayList<String>());
            //查询站点图片信息
            //TODO 暂时没有图片
            //查询站点收费信息
            if (tStationinfo.getTimetype()==1){//分段收费
                TPricepartdescExample example = new TPricepartdescExample();
                TPricepartdescExample.Criteria criteria = example.createCriteria();
                criteria.andStationidEqualTo(tStationinfo.getStationid());
                List<TPricepartdesc> tPricepartdescs=tPricepartdescMapper.selectByExample(example);
                List<PricePartDescInfo> pricePartDesc = new ArrayList<PricePartDescInfo>();
                for (TPricepartdesc tPricepartdesc:tPricepartdescs){
                    PricePartDescInfo pricePartDescInfo = new PricePartDescInfo();
                    pricePartDescInfo.setSlotElecPrice(tPricepartdesc.getSlotelecprice());
                    pricePartDescInfo.setSlotFlag(tPricepartdesc.getSlotflag());
                    pricePartDescInfo.setSlotPrice(tPricepartdesc.getSlotprice());
                    pricePartDescInfo.setSlotServicePrice(tPricepartdesc.getSlotserviceprice());
                    pricePartDescInfo.setTimeDesc(tPricepartdesc.getTimedesc());
                    pricePartDesc.add(pricePartDescInfo);
                }
                Map<String,List<PricePartDescInfo>> price = new HashMap<String, List<PricePartDescInfo>>();
                price.put("PriceInfo",pricePartDesc);
                List desc =  new ArrayList<Map<String, List<PricePartDescInfo>>>();
                desc.add(price);
                stationInfo.setPricePartDesc(desc);
            }else {
                Map<String,List<PricePartDescInfo>> price = new HashMap<String, List<PricePartDescInfo>>();
                price.put("PriceInfo",new ArrayList<PricePartDescInfo>());
                List desc =  new ArrayList<Map<String, List<PricePartDescInfo>>>();
                desc.add(price);
                stationInfo.setPricePartDesc(desc);
            }
            //查询站点充电桩信息
            TEquipmentinfoExample example = new TEquipmentinfoExample();
            TEquipmentinfoExample.Criteria criteria = example.createCriteria();
            criteria.andStationidEqualTo(tStationinfo.getStationid());
            List<TEquipmentinfo> tEquipmentinfos= tEquipmentinfoMapper.selectByExample(example);
            List<EquipmentInfo> equipmentInfos = new ArrayList<EquipmentInfo>();
            for (TEquipmentinfo tEquipmentinfo:tEquipmentinfos){
                EquipmentInfo equipmentInfo = new EquipmentInfo();
                equipmentInfo.setEquipmentID(tEquipmentinfo.getEquipmentid());
                equipmentInfo.setManufacturerID(tEquipmentinfo.getManufacturerid());
                equipmentInfo.setManufacturerName(tEquipmentinfo.getManufacturername());
                equipmentInfo.setEquipmentModel(tEquipmentinfo.getEquipmentmodel());
                equipmentInfo.setEquipmentName(tEquipmentinfo.getEquipmentname());
                equipmentInfo.setProductionDate(tEquipmentinfo.getProductiondate());
                equipmentInfo.setEquipmentType(tEquipmentinfo.getEquipmenttype());
                equipmentInfo.setPower(tEquipmentinfo.getPower());
                equipmentInfo.setNationalStandard(tEquipmentinfo.getNationalstandard());
                equipmentInfo.setEquipmentLng(tEquipmentinfo.getEquipmentlng());
                equipmentInfo.setEquipmentLat(tEquipmentinfo.getEquipmentlat());
                //查询充电接口信息
                TConnectorinfoExample tConnectorinfoExample = new TConnectorinfoExample();
                TConnectorinfoExample.Criteria criteria1 = tConnectorinfoExample.createCriteria();
                criteria1.andEquipmentidEqualTo(tEquipmentinfo.getEquipmentid());
                List<TConnectorinfo> tConnectorinfos= tConnectorinfoMapper.selectByExample(tConnectorinfoExample);
                List<ConnectorInfo> connectorInfos = new ArrayList<ConnectorInfo>();
                for (TConnectorinfo tConnectorinfo:tConnectorinfos){
                    ConnectorInfo connectorInfo = new ConnectorInfo();
                    connectorInfo.setConnectorID(tConnectorinfo.getConnectorid());
                    connectorInfo.setConnectorName(tConnectorinfo.getConnectorname());
                    connectorInfo.setConnectorType(tConnectorinfo.getConnectortype());
                    connectorInfo.setParkNo(tConnectorinfo.getParkno());
                    connectorInfo.setPower(tConnectorinfo.getPower());
                    connectorInfo.setRatedCurrent(tConnectorinfo.getRatedcurrent());
                    connectorInfo.setVoltageLowerLimits(tConnectorinfo.getVoltagelowerlimits());
                    connectorInfo.setVoltageUpperLimits(tConnectorinfo.getVoltageupperlimits());
                    connectorInfos.add(connectorInfo);
                }
                equipmentInfo.setConnectorInfos(connectorInfos);
                equipmentInfos.add(equipmentInfo);
            }
            stationInfo.setEquipmentInfos(equipmentInfos);
            stationInfos.add(stationInfo);
        }
        stationInfoPage.setStationInfos(stationInfos);
        stationInfoPage.setPageNo(page.getPageNum());
        stationInfoPage.setPageSize(page.getPageSize());
        stationInfoPage.setPageCount(Long.valueOf(page.getPages()));
        stationInfoPage.setItemSize(page.getTotal());
        TResponse<StationInfoPage> resp = new TResponse<StationInfoPage>(stationInfoPage);
        return resp;
    }

    public TResponse<Map<String, Object>> queryStationStatus(List<String> StationIDs) throws IOException{

        Integer Total = 0;

        PowerstationExample powerstationExample = new PowerstationExample();
        PowerstationExample.Criteria criteria = powerstationExample.createCriteria();
        criteria.andStationnoIn(StationIDs);
        //根据充电站id查询接口信息
        List<Powerstation> powerstations= powerstationMapper.selectByExample(powerstationExample);
        List<StationStatusInfo> stationStatusInfos = new ArrayList<StationStatusInfo>();
        for (Powerstation powerstation:powerstations){
            if (powerstation.getStationid()!=null){
                //
                DevicestatusinfoExample devicestatusinfoExample = new DevicestatusinfoExample();
                DevicestatusinfoExample.Criteria criteria1 = devicestatusinfoExample.createCriteria();
                criteria1.andStationidEqualTo(powerstation.getStationid());
                List<Devicestatusinfo> devicestatusinfos= devicestatusinfoMapper.selectByExample(devicestatusinfoExample);
                StationStatusInfo stationStatusInfo = new StationStatusInfo();
                stationStatusInfo.setStationID(powerstation.getStationno());
                List<ConnectorStatusInfo> connectorStatusInfos = new ArrayList<ConnectorStatusInfo>();
                for (Devicestatusinfo devicestatusinfo:devicestatusinfos){
                    Total++;
                    ConnectorStatusInfo connectorStatusInfo = new ConnectorStatusInfo();

                    Byte port=devicestatusinfo.getPort();
                    if (port.equals(new Byte("65"))){//A
                        connectorStatusInfo.setConnectorID(devicestatusinfo.getDeviceid()+"A");
                    }else {
                        connectorStatusInfo.setConnectorID(devicestatusinfo.getDeviceid()+"B");
                    }
                    if (devicestatusinfo.getStatus()==100){
                        connectorStatusInfo.setStatus(0);
                    }else if (devicestatusinfo.getStatus()==0){
                        connectorStatusInfo.setStatus(1);
                    }else if (devicestatusinfo.getStatus()==1){
                        connectorStatusInfo.setStatus(3);
                    }else if (devicestatusinfo.getStatus()==7){
                        connectorStatusInfo.setStatus(255);
                    }else if (devicestatusinfo.getStatus()>7){
                        connectorStatusInfo.setStatus(2);
                    }else {
                        connectorStatusInfo.setStatus(2);
                    }
                    connectorStatusInfo.setCurrentA(0);
                    connectorStatusInfo.setCurrentB(0);
                    connectorStatusInfo.setCurrentC(0);
                    connectorStatusInfo.setVoltageA(0);
                    connectorStatusInfo.setVoltageB(0);
                    connectorStatusInfo.setVoltageC(0);
                    connectorStatusInfo.setParkStatus(0);
                    connectorStatusInfo.setLockStatus(0);//地锁
                    connectorStatusInfo.setSOC(0);
                    connectorStatusInfos.add(connectorStatusInfo);
                }

                stationStatusInfo.setConnectorStatusInfos(connectorStatusInfos);
                stationStatusInfos.add(stationStatusInfo);
            }
        }
        Map<String,Object> resMap= new HashMap<String, Object>();
        resMap.put("StationStatusInfos",stationStatusInfos);
        resMap.put("Total",Total);
        TResponse<Map<String, Object>> resp = new TResponse<Map<String, Object>>(resMap);
        return resp;
    }

    public TResponse<QueryEquipAuthRes> queryEquipAuth(QueryEquipAuthReq equipAuthReq) throws IOException {
        DevicestatusinfoExample devicestatusinfoExample = new DevicestatusinfoExample();
        DevicestatusinfoExample.Criteria criteria1 = devicestatusinfoExample.createCriteria();
        String connectorID = equipAuthReq.getConnectorID();
        criteria1.andDeviceidEqualTo(connectorID.substring(0,connectorID.length()-1));
        connectorID=connectorID.substring(connectorID.length()-1);
        if (connectorID.equals("A")){
            criteria1.andPortEqualTo(Byte.valueOf("65"));
          }else {
            criteria1.andPortEqualTo(Byte.valueOf("66"));
        }
        List<Devicestatusinfo> devicestatusinfos=devicestatusinfoMapper.selectByExample(devicestatusinfoExample);
        QueryEquipAuthRes equipAuthRes = new QueryEquipAuthRes();
        equipAuthRes.setConnectorID(equipAuthReq.getConnectorID());
        equipAuthRes.setEquipAuthSeq(equipAuthReq.getEquipAuthSeq());
        if (devicestatusinfos.size()!=0){
            Devicestatusinfo devicestatusinfo=devicestatusinfos.get(0);
            equipAuthRes.setFailReason(0);
            if (devicestatusinfo.getStatus()==100){
                equipAuthRes.setSuccStat(3);//离线
            }else if (devicestatusinfo.getStatus()==0){
                equipAuthRes.setSuccStat(0);//空闲
            }else if (devicestatusinfo.getStatus()==1){
                equipAuthRes.setSuccStat(4);//占用
            }else if (devicestatusinfo.getStatus()==7){
                equipAuthRes.setSuccStat(5);//故障
            }else if (devicestatusinfo.getStatus()>7){
                equipAuthRes.setSuccStat(6);//充电中
            }else {
                equipAuthRes.setSuccStat(2);
            }
        }else {
            equipAuthRes.setFailReason(1);
            equipAuthRes.setSuccStat(2);
        }

        TResponse<QueryEquipAuthRes> response = new TResponse<QueryEquipAuthRes>(equipAuthRes);
        return response;
    }

    public TResponse<QueryEquipBusinessPolicyResForFD> QueryEquipBusinessPolicy(QueryEquipBusinessPolicyReqForFD reqForFD) {

        String deviceId = reqForFD.getConnectorID().substring(0,reqForFD.getConnectorID().length() - 1);
        if (deviceId==null||"".equals(deviceId)){
            TResponse<QueryEquipBusinessPolicyResForFD> response=new TResponse();
            response.setMsg("数据为空");
            response.setRet("500");
            response.setData(new QueryEquipBusinessPolicyResForFD());
            return response;
        }
        QueryEquipBusinessPolicyResForFD equipBusinessPolicyResForFD = new QueryEquipBusinessPolicyResForFD();
        //查询服务费
        Pricehistory pricehistory=pricehistoryMapper.selectDeviceIdTop(deviceId,1);
        if (pricehistory==null){
            TResponse<QueryEquipBusinessPolicyResForFD> response=new TResponse();
            response.setMsg("数据异常");
            response.setRet("500");
            response.setData(new QueryEquipBusinessPolicyResForFD());
            return response;
        }
        //时段费用
        JfpgpriceExample jfpgpriceExample = new JfpgpriceExample();
        JfpgpriceExample.Criteria criteria = jfpgpriceExample.createCriteria();
        criteria.andStationidEqualTo(pricehistory.getStationid());
        List<Jfpgprice> jfpgpriceList=jfpgpriceMapper.selectByExample(jfpgpriceExample);
        if (jfpgpriceList.size()==0){
            return null;
        }
        //构造出参
        equipBusinessPolicyResForFD.setConnectorID(reqForFD.getConnectorID());
        equipBusinessPolicyResForFD.setEquipBizSeq(reqForFD.getEquipBizSeq());
        equipBusinessPolicyResForFD.setFailReason(0);
        ArrayList<PolicyInfo> policyInfos = new ArrayList<PolicyInfo>();
        for (Jfpgprice jfpgprice:jfpgpriceList){
            PolicyInfo policyInfo = new PolicyInfo();
            policyInfo.setElecPrice(jfpgprice.getPrice());
            policyInfo.setSevicePrice(pricehistory.getServiceprice());
            policyInfo.setStartTime(jfpgprice.getStarttime().replace(":","")+"00");
            policyInfos.add(policyInfo);
        }
        equipBusinessPolicyResForFD.setPolicyInfos(policyInfos);
        equipBusinessPolicyResForFD.setSuccStat(0);
        equipBusinessPolicyResForFD.setSumPreiod(jfpgpriceList.size());
        TResponse<QueryEquipBusinessPolicyResForFD> response = new TResponse<QueryEquipBusinessPolicyResForFD>(equipBusinessPolicyResForFD);
        return response;
    }

    @Override
    public TResponse<QueryEquipChargeStatsResForFD> queryEquipChargeStatus(QueryEquipChargeStatsReqForFD queryEquipChargeStatsReqForFD) {
        TResponse<QueryEquipChargeStatsResForFD> response=new TResponse();
        QueryEquipChargeStatsResForFD queryEquipChargeStatsResForFD = new QueryEquipChargeStatsResForFD();
        OrderDO orderDO=orderMapper.selectByOrderId(queryEquipChargeStatsReqForFD.getStartChargeSeq());
        Chargesession chargesession=chargesessionMapper.selectByOrderId(queryEquipChargeStatsReqForFD.getStartChargeSeq());
        if (null!=orderDO&&null!=chargesession){
            Devicestatusinfo devicestatusinfos;
            if (orderDO.getDeviceport().equals("A")){
                devicestatusinfos=devicestatusinfoMapper.selectByDeviceIdAndPort(orderDO.getDeviceid(),Byte.valueOf("65"));
            }else {
                devicestatusinfos=devicestatusinfoMapper.selectByDeviceIdAndPort(orderDO.getDeviceid(),Byte.valueOf("66"));
            }

            queryEquipChargeStatsResForFD.setStartChargeSeq(queryEquipChargeStatsReqForFD.getStartChargeSeq());//充电订单号
            switch (orderDO.getOrderstatus()){
                case 0:
                    //未结算
                    queryEquipChargeStatsResForFD.setStartChargeSeqStat(2);//充电中
                    break;
                case 1:
                    //已结算
                    queryEquipChargeStatsResForFD.setStartChargeSeqStat(4);//已结束
                    break;
                case 2:
                    //已冻结
                    queryEquipChargeStatsResForFD.setStartChargeSeqStat(3);//停止中
                    break;
                case 3:
                    //已取消
                    queryEquipChargeStatsResForFD.setStartChargeSeqStat(4);//已结束
                    break;
            }
            queryEquipChargeStatsResForFD.setConnectorID(orderDO.getDeviceid()+orderDO.getDeviceport());//充电接口 65 A 66 B

            if (devicestatusinfos.getStatus()==100){
                queryEquipChargeStatsResForFD.setConnectorStats(0);
            }else if (devicestatusinfos.getStatus()==0){
                queryEquipChargeStatsResForFD.setConnectorStats(1);
            }else if (devicestatusinfos.getStatus()==1){
                queryEquipChargeStatsResForFD.setConnectorStats(3);
            }else if (devicestatusinfos.getStatus()==7){
                queryEquipChargeStatsResForFD.setConnectorStats(255);
            }else if (devicestatusinfos.getStatus()>7){
                queryEquipChargeStatsResForFD.setConnectorStats(2);
            }
            queryEquipChargeStatsResForFD.setCurrentA(chargesession.getCurrent().floatValue());//电流
            queryEquipChargeStatsResForFD.setVoltageA(chargesession.getVoltage().floatValue());//电压
            queryEquipChargeStatsResForFD.setSoc(chargesession.getPercent().floatValue());//电池剩余电量
            String startTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(chargesession.getCreatedate());
            queryEquipChargeStatsResForFD.setStartTime(startTime);//充电开始时间
            String endTime = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(chargesession.getDataupdatedate());
            queryEquipChargeStatsResForFD.setEndTime(endTime);//本次采样时间
            queryEquipChargeStatsResForFD.setTotalPower(chargesession.getAmountcharged().floatValue());//充电电量


            queryEquipChargeStatsResForFD.setChargeDetails(new ArrayList<ChargeDetail>());


            response = new TResponse<QueryEquipChargeStatsResForFD>(queryEquipChargeStatsResForFD);
        }else {
             response.setMsg("数据异常");
            response.setRet("500");
            response.setData(new QueryEquipChargeStatsResForFD());
        }


        return response;

    }

    @Override
    public TResponse<StationStatsInfo> queryStationStats(QueryStationStats queryStationStats) {
        TResponse<StationStatsInfo> tResponse = new TResponse<StationStatsInfo>();


        List<OrderDO> orderDOList =orderMapper.queryStationStats(queryStationStats);
        if (orderDOList!=null||orderDOList.size()!=0){//空验证
            StationStatsInfo stationStatsInfo = new StationStatsInfo();
            stationStatsInfo.setEndTime(queryStationStats.getEndTime());
            stationStatsInfo.setStartTime(queryStationStats.getStartTime());
            stationStatsInfo.setStationID(queryStationStats.getStationID());
            List<EquipmentStatsInfo> equipmentStatsInfoList = new ArrayList<EquipmentStatsInfo>();


            BigDecimal stationQuantity= new BigDecimal(0);//电站统计
            Iterator<OrderDO> orderIterator=  orderDOList.iterator();
            Map<String,List<ConnectorStatsInfo>> Equipment = new HashMap<String, List<ConnectorStatsInfo>>();
            while (orderIterator.hasNext()){ //接口统计
                EquipmentStatsInfo equipmentStatsInfo = new EquipmentStatsInfo();
                OrderDO orderDO=orderIterator.next();
                List<ConnectorStatsInfo> connList= Equipment.get(orderDO.getDeviceid());
                if (connList==null){//等于空
                    connList = new ArrayList<ConnectorStatsInfo>();
                    ConnectorStatsInfo connectorStatsInfo = new ConnectorStatsInfo();
                    connectorStatsInfo.setConnectorElectricity(orderDO.getQuantity());
                    connectorStatsInfo.setConnectorID(orderDO.getDeviceid()+orderDO.getDeviceport());
                    connList.add(connectorStatsInfo);
                    equipmentStatsInfo.setConnectorStatsInfos(connList);//接口列表
                    equipmentStatsInfo.setEquipmentID(orderDO.getDeviceid());//桩id
                    Equipment.put(orderDO.getDeviceid(),connList);
                    equipmentStatsInfoList.add(equipmentStatsInfo);
                }else {
                    ConnectorStatsInfo connectorStatsInfo = new ConnectorStatsInfo();
                    connectorStatsInfo.setConnectorElectricity(orderDO.getQuantity());
                    connectorStatsInfo.setConnectorID(orderDO.getDeviceid()+orderDO.getDeviceport());
                    connList.add(connectorStatsInfo);
                    BigDecimal EquipmentQuantity=connList.get(0).getConnectorElectricity();//桩统计
                    equipmentStatsInfo.setEquipmentElectricity(EquipmentQuantity.add(orderDO.getQuantity()));//桩电量
                }
                stationQuantity=stationQuantity.add(orderDO.getQuantity());//统计所有的电量
            }
            stationStatsInfo.setStationElectricity(stationQuantity);//统计电量
            stationStatsInfo.setEquipmentStatsInfos(equipmentStatsInfoList);//桩状态
            tResponse = new TResponse<StationStatsInfo>(stationStatsInfo);
        }else {
            tResponse.setMsg("数据异常");
            tResponse.setRet("500");
            tResponse.setData(new StationStatsInfo());
        }
        return tResponse;
    }

    private TResponse<TokenInfo> genErrorResp() {
        TResponse<TokenInfo> resp = new TResponse<TokenInfo>();
        resp.setSig("0");
        resp.setData(null);
        resp.setMsg("4001");
        resp.setRet("0");
        return resp;
    }
    private TResponse<TokenInfo> genSuccessResp(TokenInfo tokenInfo, String sig) {
        TResponse<TokenInfo> resp = new TResponse<TokenInfo>();
        resp.setSig(sig);
        resp.setData(tokenInfo);
        resp.setMsg("success");
        resp.setRet("0");
        return resp;
    }
    private TResponse<TokenInfo> genSuccessResp(TokenInfo tokenInfo) {
        TResponse<TokenInfo> resp = new TResponse<TokenInfo>();
        resp.setData(tokenInfo);
        resp.setMsg("success");
        resp.setRet("0");
        return resp;
    }
}
